<template>
	<view class="" style="background: #fff;">
		<view class="repair">
			<view class="uni-title" style="width: 30%;">申请人：</view>
			<view class="uni-title" style="width: 70%;">{{active.applicant}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">职位：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.field_personnel_rolename}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">开始时间：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.start_time}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">结束时间：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.end_time}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">公司名：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.field_personnel_company}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">外出地址：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.field_personnel_place}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">外出内容：</view>
			<view class="uni-title" style="width: 70%;">{{Fielddata.field_personnel_cause}}</view>
		</view>
		<view class="repair">
			<view class="uni-title" style="width: 30%;">审批意见：</view>
			<textarea class="uni-title" style="width: 70%;height: 70upx;" placeholder="请填写意见" @input="textreasons"/>
		</view>
		<view class="repair" v-if="user!==''">
			<view class="uni-title" style="width: 30%;">审批人：</view>
				<view class="uni-list-cell-db">
					<picker-c @change="handleApprover" :aList="aList"></picker-c>
				</view>
		</view>
		<button type="primary" class="btn" @click="Approvalclick" :id="true">同意</button>
		<button type="warn" class="btn" :id="false" @click="Approvalclick">不同意</button>
	</view>
</template>

<script>
	import {apipassField,apigetProcessList,apigetFielddata} from '@/common/api.js'
	export default{
		name:'Approval',
		data(){
			return{
				Fielddata:[],
				reasons:'',
				id:'',
				user:'',
				aList:[],
				hisComment:[],
				active:{}
			}
		},
		onLoad(e){
		this.active=JSON.parse(e.active)
		this.id=this.active.BUSINESS_KEY_.split('.')[1]
		//获取外勤单的数据
		apigetFielddata({id:this.id}).then(res=>{
			console.log(res)
			this.Fielddata=res.data.data
			this.hisComment=res.data.hisComment
			console.log(this.hisComment)
		})
		// 获取当前流程节点和审核人
			this.getpress()
		},
		created(){
			
		},
		methods:{
			getpress(){
				let data={
					taskid: this.active.ID_, //(必填)流程任务id
				    processInstanceId: this.active.PROC_INST_ID_, //(必填)流程实例id
				    key: "findFieldpView", //(必填)流程定义key
				    position: this.active.role_name, //(必填)申请人角色
				    type: "" //(必填)新增new/运行中
					}
				apigetProcessList(data).then(res=>{
					let userTaskName = res.data.userlist.userTaskName;
					this.aList=res.data.userlist.userList?res.data.userlist.userList:[]
					this.user=userTaskName === "结束"?0:this.aList&&this.aList!=""?this.aList[0]:""
				})
			},
			handleApprover(e){
				this.user = e
			},
			textreasons(e){
				this.reasons=e.detail.value
			},
			Approvalclick(e){
				if(this.user===""){
					this.toast('审核人为空不能提交！')
					return
				}
				if(this.reasons===""){
					this.toast('请填写审核意见！')
					return
				}
				let sign=e.currentTarget.id
				let data={
					"taskid":this.id,
					"userid":this.user.userid,
					"reasons":this.reasons,
					"sign":sign
				}
				uni.showModal({
					content:'确定提交吗？'
				}).then(res=>{
					if(res[1].confirm){
				apipassField(data).then(res=>{
					let msg="已审批通过"
					if(sign=="false"){
						msg="已驳回"
					}
					if(res.data){
						this.toast(msg)
						setTimeout(()=>{
							uni.navigateBack({
								delta:2
							})
						},1200)
					}
				})
				}else{
					console.log('取消')
				}
				})
			},
			toast(title,icon='none'){
				uni.showToast({
					title: title,
					mask: true,
					icon:icon,
					duration: 1500
				});
			}
		}
	}
</script>

<style scoped>
	.repair{
		display: flex;
		align-items:center;
		padding: 20upx 30upx;
		box-sizing:border-box;
		border-bottom: 1px solid #eee;
	}
	.btn{
		margin: 30upx;
	}
</style>
